package com.zyy.java8.samples.misc;

import java.lang.annotation.*;

/**
 * @author zhangyiying
 * @ClassName: Annotation1
 * @Description: Repeatable -- 在需要对同一种注解多次使用时，往往需要借助@Repeatable
 *              https://blog.csdn.net/ljcgit/article/details/81708679
 * @date 2022/2/8 9:45
 */
public class Annotation1 {

    // ElementType.TYPE_USE: https://blog.csdn.net/qq_45593068/article/details/121105372
    // 通过反射拿到ElementType.TYPE_USE修饰的注解可以用get…Type()方法获取

    @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
    @interface MyAnnotation {

    }

    @Retention(RetentionPolicy.RUNTIME)
    @interface Hints {
        Hint[] value();
    }
    @Repeatable(Hints.class)
    @interface Hint {
        String value();
    }

    @Hint("Hint1")
    @Hint("Hint2")
    class Person{

    }

    public static void main(String[] args) {
        Hint hint = Person.class.getAnnotation(Hint.class);
        //null
        System.out.println(hint);

        Hints hints1 = Person.class.getAnnotation(Hints.class);
        //2
        System.out.println(hints1.value().length);

        Hint[] hints2 = Person.class.getAnnotationsByType(Hint.class);
        //2
        System.out.println(hints2.length);


    }

}
